<?php
require_once("./vo/com/artxis/cms/vo/AccountVO.php");
require_once("config.php");
class LoginService {
     	function LoginService(){
			//connect to the database.
			$mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
			mysql_select_db(DATABASE_NAME);
    	}
  public function login(LoginVO $loginVO)
    {	      	
        $usrname=$loginVO->username;
        $pass   = $loginVO->password;
        $sql = mysql_query("SELECT*FROM userauth WHERE userName='$usrname' AND userPassword='$pass'");
        if (mysql_num_rows($sql) >0)
		{
 	        $tableDatax = mysql_fetch_array($sql); 
			$accountVO = new AccountVO(); 
            $accountVO->accountid 	= 1;
			$accountVO->username    = $tableDatax["userName"];
			$accountVO->password    = $tableDatax["userPassword"];
     	    $accountVO->type      	= $tableDatax["userType"];
			$accountVO->userGroup 	= $tableDatax["userGroup"];
			$accountVO->userEmail 	= $tableDatax["userEmail"];

             
			return $accountVO;
		}
		else
		{
			$accountVO = new AccountVO(); 
            $accountVO->accountid 	= 0;
			$accountVO->username    = "";
			$accountVO->password    = "";
     	    $accountVO->type      	= "";
			$accountVO->userGroup 	= "";
			$accountVO->userEmail 	= "";
			return $accountVO;			
		}

    }

}

?>